﻿Imports OMANE.Common
Imports OMANE.Common.UI

''' <summary>
''' Classe  représentant le module CRT
''' </summary>
''' <remarks></remarks>
Public Class CRTModule
    Implements IModule

    Friend Shared _Application As Common.Application
    Private _ts As VMTableauSuivi

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private ReadOnly Property Dependencies As IEnumerable(Of Common.ModuleReference) Implements Common.IModule.Dependencies
        Get
            Throw New NotImplementedException()
        End Get
    End Property

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub Load() Implements Common.IModule.Load
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="Application"></param>
    ''' <remarks></remarks>
    Private Sub Reset(ByVal Application As Common.Application) Implements Common.IModule.Reset
        Dim uiservice = Application.GetService(Of IUIService)()

        Dim dic = New Windows.ResourceDictionary()
        dic.Source = New Uri("/OMANE.Modules.CRT;component/Ressources/Ressources.xaml", System.UriKind.Relative)
        uiservice.AddResourceDictionary(dic)

        Dim m1 As New ViewModelMainMenuItem() With {.Title = "Gestionnaire CRT"}
        m1.Children.Add(New ViewModelMainMenuItem() With {.Title = "Suivi et Planification"})
        m1.Children.Add(New ViewModelMainMenuItem() With {.Title = "Outils"})
        m1.Children.Add(New ViewModelMainMenuItem() With {.Title = "Options"})
        m1.Children.Add(New ViewModelMainMenuItem() With {.Title = "A Propos", .Command = Sub(obj) MainMenuClick("A Propos")})
        m1.Children(0).Children.Add(New ViewModelMainMenuItem() With {.Title = "Mettren A Jour TBB", .Command = Sub(obj) MainMenuClick("Mettren A Jour TBB")})

        uiservice.ViewModelMainMenu.Children.Add(m1)

        Dim suivi As New Common.UI.V2ViewModelTabGroup With { _
           .Title = "Suivi",
           .TabGroup = New ObjectModel.ObservableCollection(Of Common.UI.IViewModelTabSection)}

        ' suivi.TabGroup.Add(New VMDashBoard())
        Dim ts = New VMTableauSuivi()
        Me._ts = ts
        ts.InitialisationTables.Add(New InitialisationTable("Primes", "C:\Users\Consultant\Desktop\test\Primes.txt"))
        ts.InitialisationTables.Add(New InitialisationTable("Sinistres", "C:\Users\Consultant\Desktop\test\Sinistres.txt"))
        ts.InitialisationTables.Add(New InitialisationTable("Provisions Début", "C:\Users\Consultant\Desktop\test\ProvisionsDebut.txt"))
        ts.InitialisationTables.Add(New InitialisationTable("Données Externes", "C:\Users\Consultant\Desktop\test\DonneesExternes.txt"))
        ts.InitialisationTables.Add(New InitialisationTable("Histo PM", "C:\Users\Consultant\Desktop\test\HistoPM.txt"))
        ts.InitialisationTables.Add(New InitialisationTable("Parametres", "C:\Users\Consultant\Desktop\test\Parametres.txt"))


        suivi.TabGroup.Add(ts)
        ts.Steps.Add( _
            New VMStep() With {.Title = "Initialisation"})
        ts.Steps.Add( _
           New VMStep(ts.Steps(0)) With {.Title = "Provisionnement"})
        ts.Steps.Add( _
           New VMStep(ts.Steps(1)) With {.Title = "Historisation"})
       

        Dim init = ts.Steps(0)
        init.StartStep = New VMStep() With {.Title = "Donnees et Parametres"}
        init.StartStep.AddAfter("Calcul SAS").AddAfter("Creation des fichiers de provisionnement")
        init.StartStep.NextStep.Element = New VMSASComputationElement()

        Dim tbb As New Common.UI.V2ViewModelTabGroup With { _
                    .Title = "Tableau de Bord",
                    .TabGroup = suivi.TabGroup, _
                    .TabSection = suivi.TabGroup(0)}
        suivi.Children.Add(tbb)

        Dim outils As New Common.UI.V2ViewModelTabGroup With { _
           .Title = "Outils",
           .TabGroup = New ObjectModel.ObservableCollection(Of Common.UI.IViewModelTabSection)}

        outils.TabGroup.Add(New VMParametrage() With {.Title = "CRT_SAS_V9"})
        outils.TabGroup.Add(New VMParametrage() With {.Title = "CRT_MODELE_2003_GENERATOR_t14"})

        Dim p As VMParametrage = outils.TabGroup(1)
        p.Parametres.Add(New VMParametrageElement("Modele excel de provisionnement", "fileselector"))
        p.Parametres.Add(New VMParametrageElement("Onglet De la Maquette-TCD"))
        p.Parametres.Add(New VMParametrageElement("Onglet des parametres"))
        p.Parametres.Add(New VMParametrageElement("Dossier des données source", "folderselector"))
        p.Parametres.Add(New VMParametrageElement("Dossier de  Destination", "folderselector"))
        p.Parametres.Add(New VMParametrageElement("Dossier de validation", "folderselector"))
        p.Parametres.Add(New VMParametrageElement("Nettoyer les dossiers", "yesno"))
        p.Parametres.Add(New VMParametrageElement("Periodicite de l'arrete", "selector", New String() {"Par defaut", "Trimestriel", "Mensuel"}) With {.Groupe = "Info Arrete"})
        p.Parametres.Add(New VMParametrageElement("Numero de l'Arrete", "selector", New String() {"T1", "T2", "T3", "T4"}) With {.Groupe = "Info Arrete"})
        p.Parametres.Add(New VMParametrageElement("Annee de l'Arrete") With {.Groupe = "Info Arrete"})
        p.Parametres.Add(New VMParametrageElement("Information Arrete") With {.Groupe = "Info Arrete"})
        p.Parametres.Add(New VMParametrageElement("Transformer code Banque", "yesno"))
        p.Parametres.Add(New VMParametrageElement("Colonne  code banque"))
        p.Parametres.Add(New VMParametrageElement("Perimetres A generer", "multiselector", New String() {"NORMALIS", "AGRILIS", "BP2007", "BP2008", "BP2009", "BP2010", "BP2011", "BP2012"}))


        Dim sas As New Common.UI.V2ViewModelTabGroup With { _
           .Title = "SAS",
           .TabGroup = outils.TabGroup,
           .TabSection = outils.TabGroup(0)}

        Dim generateur As New Common.UI.V2ViewModelTabGroup With { _
           .Title = "Generateur",
           .TabGroup = outils.TabGroup,
           .TabSection = outils.TabGroup(1)}

        Dim referentielcrt As New Common.UI.V2ViewModelTabGroup With { _
           .Title = "Referentiel"}

        Dim refcrt As New EXCELReferentielCRT("c:\users\consultant\desktop\input_crt_omane_paramcomptes_2012t3.xls")

        Dim tablesviews = refcrt.InfoTables.Select(Function(info) CType(New VMTableView(refcrt, info), Common.UI.IViewModelTabSection)).ToList()

        Dim tablesreferentielcrt As New Common.UI.V2ViewModelTabGroup With { _
           .Title = "Tables",
           .TabGroup = New ObjectModel.ObservableCollection(Of Common.UI.IViewModelTabSection)(tablesviews)}

        tablesreferentielcrt.TabSection = tablesreferentielcrt.TabGroup(0)

        Dim gestionreferentielcrt As New Common.UI.V2ViewModelTabGroup With { _
          .Title = "Gestion",
          .TabGroup = New ObjectModel.ObservableCollection(Of Common.UI.IViewModelTabSection)()}

        gestionreferentielcrt.TabGroup.Add(New VMGestionComptes(TestDataSet))

        gestionreferentielcrt.TabSection = gestionreferentielcrt.TabGroup(0)


        referentielcrt.Children.Add(tablesreferentielcrt)
        referentielcrt.Children.Add(gestionreferentielcrt)

        outils.Children.Add(sas)
        outils.Children.Add(generateur)
        outils.Children.Add(referentielcrt)




        _Application = Application
        Dim root = Me.UIRoot

        root.Children.Add(suivi)
        root.Children.Add(outils)

    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub Unload() Implements Common.IModule.Unload

    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Friend ReadOnly Property Application As Common.Application
        Get
            Return _Application
        End Get
    End Property

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Friend ReadOnly Property UIRoot As IViewModelTrvMenuItem
        Get
            Return Application.GetService(Of IUIService).V2ViewModelAccordeonMenu.Inventaires.Body.Root
        End Get
    End Property

    ''' <summary>
    ''' Gestionnaire de l'evenement click du menu principal
    ''' </summary>
    ''' <param name="name"></param>
    ''' <remarks></remarks>
    Private Sub MainMenuClick(ByVal name As String)
        If name = "A Propos" Then
            Dim uiservice = Application.GetService(Of IUIService)()
            uiservice.ShowMessage("Module CRT Créé par l'équipe PSP ave c le soutien de l'ADE")
        End If
        If name = "Mettren A Jour TBB" Then
            _ts.Refresh()
        End If
    End Sub

    Friend Shared TestDataSet As Data.DataSet = New Data.DataSet

End Class

